/**
 * 
 */
package travibot.ui.gui.forms.listeners;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;
import travibot.model.Village;
import travibot.ui.gui.forms.CityList;
import travibot.ui.gui.forms.viewers.CityListViewer;


/**
 * @author tajzivit
 *
 */
public class CityListSelectionChangedListener implements ISelectionChangedListener {

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
     */
    public void selectionChanged(SelectionChangedEvent arg0) {

        if(arg0.getSelection().isEmpty())
            return;
        
        TreeSelection selection = (TreeSelection)arg0.getSelection();
        
        Village village = (Village)selection.getFirstElement();
        
        CityListViewer viewer = (CityListViewer)arg0.getSource();
        
        CityList cityList = (CityList)viewer.getTree().getParent();
        
        cityList.getMainForm().updateFieldsTab(village);
        cityList.getMainForm().updateBuildingsTab(village);
    }
}
